/*     */ package cn.zzuisa.news.repository.dao;

/*     */
/*     */ import cn.zzuisa.news.entity.IprNewsInfo;
/*     */ import cn.zzuisa.news.entity.IprNewsType;
/*     */ import cn.zzuisa.news.form.IprNewsInfoForm;
/*     */ import cn.zzuisa.news.repository.IprNewsRepository;
/*     */ import cn.zzuisa.news.util.JDBCUtil;
/*     */ import java.sql.Connection;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.sql.Statement;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;

/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */ public class IprNewsDAO/*     */ implements IprNewsRepository
/*     */ {
	Connection conn = null;
	Statement statement = null;
	ResultSet resultSet = null;
	PreparedStatement preparedStatement = null;
	/* 28 */

	/*     */ public boolean addType(String name) {
		/* 27 */ conn = JDBCUtil.getConnection();
		/* 28 */ preparedStatement = null;
		/* 29 */ resultSet = null;
		/* 30 */ int flag = 0, maxId = 0;
		/* 31 */ String maxid = "select max(id) id from ipr_news_type";
		/* 32 */ String sql = "insert into `ipr_news_type` (type,name) values(?,?)";
		/*     */
		/*     */ try {
			/* 35 */ preparedStatement = conn.prepareStatement(maxid);
			/* 36 */ preparedStatement.executeQuery();
			/* 37 */ if (resultSet.next())
				/* 38 */ maxId = resultSet.getInt("id") + 1;
			/* 39 */ preparedStatement = conn.prepareStatement(sql);
			/* 40 */ preparedStatement.setInt(1, maxId);
			/* 41 */ preparedStatement.setString(2, name);
			/* 42 */ flag = preparedStatement.executeUpdate();
			/* 43 */ } catch (SQLException e) {
			/*     */
			/* 45 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 48 */ JDBCUtil.close(conn, preparedStatement, resultSet);
				/* 49 */ } catch (Exception e) {
				/*     */
				/* 51 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 54 */ return (flag > 0);
		/*     */ }

	/*     */
	/*     */
	/*     */
	/*     */ public boolean addNewsInfo(IprNewsInfoForm iprNewsInfoForm) {
		/* 60 */ conn = JDBCUtil.getConnection();
		/* 61 */ preparedStatement = null;
		/* 62 */ ResultSet resultSet = null;
		/* 63 */ int flag = 0;
		/* 64 */ String sql = "insert into `ipr_news_info` (type,title,content,img) values(?,?,?,?)";
		/*     */
		/*     */ try {
			/* 67 */ preparedStatement = conn.prepareStatement(sql);
			/* 68 */ preparedStatement.setInt(1, iprNewsInfoForm.getType().intValue());
			/* 69 */ preparedStatement.setString(2, iprNewsInfoForm.getTitle());
			/* 70 */ preparedStatement.setString(3, iprNewsInfoForm.getContent());
			/* 71 */ preparedStatement.setString(4, iprNewsInfoForm.getImg());
			/* 72 */ flag = preparedStatement.executeUpdate();
			/* 73 */ } catch (SQLException e) {
			/*     */
			/* 75 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 78 */ JDBCUtil.close(conn, preparedStatement);
				/* 79 */ } catch (Exception e) {
				/*     */
				/* 81 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 84 */ return (flag > 0);
		/*     */ }

	/*     */
	/*     */
	/*     */ public List<IprNewsType> listtype() {
		/* 89 */ conn = JDBCUtil.getConnection();
		/* 90 */ statement = null;
		/* 91 */ resultSet = null;
		/*     */
		/* 93 */ String sql = "select * from ipr_news_type";
		/* 94 */ List<IprNewsType> list = new ArrayList<IprNewsType>();
		/*     */ try {
			/* 96 */ statement = conn.createStatement();
			/* 97 */ resultSet = statement.executeQuery(sql);
			/* 98 */ while (resultSet.next()) {
				/* 99 */ IprNewsType iprNewsType = new IprNewsType();
				/* 100 */ iprNewsType.setId(Integer.valueOf(resultSet.getInt("id")));
				/* 101 */ iprNewsType.setName(resultSet.getString("name"));
				/* 102 */ iprNewsType.setType(Integer.valueOf(resultSet.getInt("type")));
				/* 103 */ list.add(iprNewsType);
				/*     */ }
			/* 105 */ } catch (SQLException e) {
			/*     */
			/* 107 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 110 */ JDBCUtil.close(conn, statement, resultSet);
				/* 111 */ } catch (Exception e) {
				/*     */
				/* 113 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 116 */ return list;
		/*     */ }

	/*     */
	/*     */
	/*     */ public IprNewsType findIprNewsTypeById(Integer id) {
		/* 121 */ conn = JDBCUtil.getConnection();
		/* 122 */ statement = null;
		/* 123 */ resultSet = null;
		/* 124 */ IprNewsType iprNewsType = new IprNewsType();
		/*     */ try {
			/* 126 */ String sql = "select * from ipr_news_type where id = " + id;
			/* 127 */ statement = conn.createStatement();
			/* 128 */ resultSet = statement.executeQuery(sql);
			/* 129 */ if (resultSet.next()) {
				/* 130 */ iprNewsType.setId(Integer.valueOf(resultSet.getInt("id")));
				/* 131 */ iprNewsType.setName(resultSet.getString("name"));
				/* 132 */ iprNewsType.setType(Integer.valueOf(resultSet.getInt("type")));
				/*     */ }
			/* 134 */ } catch (SQLException e) {
			/*     */
			/* 136 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 139 */ JDBCUtil.close(conn, statement, resultSet);
				/* 140 */ } catch (Exception e) {
				/*     */
				/* 142 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/*     */
		/* 146 */ return iprNewsType;
		/*     */ }

	/*     */
	/*     */
	/*     */ public List<IprNewsInfo> listinfoByType(Integer type) {
		/* 151 */ conn = JDBCUtil.getConnection();
		/* 152 */ statement = null;
		/* 153 */ resultSet = null;
		/*     */
		/* 155 */ String sql = (type == null) ? "select * from ipr_news_info"
				: ("select * from ipr_news_info where type = " + type);
		/* 156 */ List<IprNewsInfo> list = new ArrayList<IprNewsInfo>();
		/*     */ try {
			/* 158 */ statement = conn.createStatement();
			/* 159 */ resultSet = statement.executeQuery(sql);
			/* 160 */ while (resultSet.next()) {
				/* 161 */ IprNewsInfo iprNewsInfo = new IprNewsInfo();
				/* 162 */ iprNewsInfo.setId(Integer.valueOf(resultSet.getInt("id")));
				/* 163 */ iprNewsInfo.setTitle(resultSet.getString("title"));
				/* 164 */ iprNewsInfo.setContent(resultSet.getString("content"));
				/* 165 */ iprNewsInfo.setType(Integer.valueOf(resultSet.getInt("type")));
				/* 166 */ iprNewsInfo.setImg(resultSet.getString("img"));
				/* 167 */ list.add(iprNewsInfo);
				/*     */ }
			/* 169 */ } catch (SQLException e) {
			/*     */
			/* 171 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 174 */ JDBCUtil.close(conn, statement, resultSet);
				/* 175 */ } catch (Exception e) {
				/*     */
				/* 177 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 180 */ return list;
		/*     */ }

	/*     */
	/*     */
	/*     */ public IprNewsInfo findInfoById(Integer id) {
		/* 185 */ conn = JDBCUtil.getConnection();
		/* 186 */ statement = null;
		/* 187 */ resultSet = null;
		/*     */
		/* 189 */ IprNewsInfo iprNewsInfo = new IprNewsInfo();
		/* 190 */ String sql = "select * from ipr_news_info where id = " + id;
		/*     */ try {
			/* 192 */ statement = conn.createStatement();
			/* 193 */ resultSet = statement.executeQuery(sql);
			/* 194 */ if (resultSet.next()) {
				/*     */
				/* 196 */ iprNewsInfo.setId(Integer.valueOf(resultSet.getInt("id")));
				/* 197 */ iprNewsInfo.setTitle(resultSet.getString("title"));
				/* 198 */ iprNewsInfo.setContent(resultSet.getString("content"));
				/* 199 */ iprNewsInfo.setType(Integer.valueOf(resultSet.getInt("type")));
				/* 200 */ iprNewsInfo.setImg(resultSet.getString("img"));
				/*     */ }
			/* 202 */ } catch (SQLException e) {
			/*     */
			/* 204 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 207 */ JDBCUtil.close(conn, statement, resultSet);
				/* 208 */ } catch (Exception e) {
				/*     */
				/* 210 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 213 */ return iprNewsInfo;
		/*     */ }

	/*     */
	/*     */
	/*     */ public boolean editById(IprNewsInfoForm iprNewsInfoForm, Integer id) {
		/* 218 */ conn = JDBCUtil.getConnection();
		/* 219 */ preparedStatement = null;
		/* 220 */ int flag = 0;
		/* 221 */ String sql = "UPDATE ipr_news_info SET title =?, content=?, img=? where id = ?";
		/*     */ try {
			/* 223 */ preparedStatement = conn.prepareStatement(sql);
			/* 224 */ preparedStatement.setString(1, iprNewsInfoForm.getTitle());
			/* 225 */ preparedStatement.setString(2, iprNewsInfoForm.getContent());
			/* 226 */ preparedStatement.setString(3, iprNewsInfoForm.getImg());
			/* 227 */ preparedStatement.setInt(4, id.intValue());
			/* 228 */ flag = preparedStatement.executeUpdate();
			/*     */ }
		/* 230 */ catch (SQLException e) {
			/*     */
			/* 232 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 235 */ JDBCUtil.close(conn, preparedStatement);
				/* 236 */ } catch (Exception e) {
				/*     */
				/* 238 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 241 */ return (flag > 0);
		/*     */ }

	/*     */
	/*     */
	/*     */ public boolean delete(Integer id) {
		/* 246 */ conn = JDBCUtil.getConnection();
		/* 247 */ preparedStatement = null;
		/* 248 */ int flag = 0;
		/* 249 */ String sql = "delete from ipr_news_info where id = ?";
		/*     */ try {
			/* 251 */ preparedStatement = conn.prepareStatement(sql);
			/* 252 */ preparedStatement.setInt(1, id.intValue());
			/* 253 */ flag = preparedStatement.executeUpdate();
			/* 254 */ } catch (SQLException e) {
			/*     */
			/* 256 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 259 */ JDBCUtil.close(conn, preparedStatement);
				/* 260 */ } catch (Exception e) {
				/*     */
				/* 262 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 265 */ return (flag > 0);
		/*     */ }
	/*     */ }

/*
 * Location:
 * /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/repository/dao/
 * IprNewsDAO.class Java compiler version: 8 (52.0) JD-Core Version: 1.0.7
 */